package com.zhudoo.zhilian.api;

import com.zhudoo.zhilian.service.AppointmentService;
import com.zhudoo.zhilian.util.web.Response;
import com.zhudoo.zhilian.util.web.ResponseUtil;
import com.zhudoo.zhilian.util.web.ServiceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author zhudao
 */
@RestController
@RequestMapping("/appointment")
public class AppointmentController {

    @Autowired
    private AppointmentService appointmentService;

    @RequestMapping(value = "/sendAppointment", method = RequestMethod.POST)
    public Response sendAppointment(@RequestHeader String token,
                                    Integer toUserId,
                                    Integer tipId,
                                    String appointmentDate,
                                    String address,
                                    String name,
                                    String phone) {
        ServiceContext serviceContext = ServiceContext.getInstance();
        serviceContext.addParams("token", token);
        serviceContext.addParams("toUserId", toUserId);
        serviceContext.addParams("tipId", tipId);
        serviceContext.addParams("appointmentDate", appointmentDate);
        serviceContext.addParams("address", address);
        serviceContext.addParams("name", name);
        serviceContext.addParams("phone", phone);
        Map<String, Object> resultMap = appointmentService.sendAppointment(serviceContext);
        return ResponseUtil.responseSuccess("生成成功", resultMap);
    }

    @RequestMapping(value = "/getAppointmentList", method = RequestMethod.GET)
    public Response getAppointmentList(@RequestHeader String token, Integer page, Integer limit, Integer status) {
        ServiceContext serviceContext = ServiceContext.getInstance();
        serviceContext.addParams("token", token);
        serviceContext.addParams("status", status);
        serviceContext.setPage(page);
        serviceContext.setLimit(limit);
        List<Map<String, Object>> resultList = appointmentService.getAppointmentList(serviceContext);
        return ResponseUtil.responseSuccess("获取成功", resultList);
    }

    @RequestMapping(value = "/getAppointment", method = RequestMethod.GET)
    public Response getAppointment(@RequestHeader String token, Integer id) {
        ServiceContext serviceContext = ServiceContext.getInstance();
        serviceContext.addParams("token", token);
        serviceContext.addParams("id", id);
        Map<String, Object> resultMap = appointmentService.getAppointmentById(serviceContext);
        return ResponseUtil.responseSuccess("获取成功", resultMap);
    }

    @RequestMapping(value = "/updateAppointment", method = RequestMethod.POST)
    public Response updateAppointment(@RequestHeader String token, Integer id, Integer status) {
        ServiceContext serviceContext = ServiceContext.getInstance();
        serviceContext.addParams("token", token);
        serviceContext.addParams("id", id);
        serviceContext.addParams("status", status);
        appointmentService.updateAppointment(serviceContext);
        return ResponseUtil.responseSuccess("修改成功");
    }

}
